<template>
  <div class="container">
    <div class="left">
      <div
        class="btn"
        :class="page == 'Home' ? 'active' : ''"
        @click="toggle('Home')"
      >
        管理中心
      </div>
      <div
        class="btn"
        :class="page == 'Goods' ? 'active' : ''"
        @click="toggle('Goods')"
      >
        商品管理
      </div>
      <div
        class="btn"
        :class="page == 'User' ? 'active' : ''"
        @click="toggle('User')"
      >
        会员管理
      </div>
      <div
        class="btn"
        :class="page == 'Order' ? 'active' : ''"
        @click="toggle('Order')"
      >
        订单管理
      </div>
    </div>
    <div class="right">
      <div class="header">头部</div>
      <div class="content">
        <!-- 调用 -->
        <keep-alive>
          <component :is="page"></component>
        </keep-alive>
      </div>
    </div>
  </div>
</template>

<script>
// 导入组件
// 模块化
import Home from "./page/Home.vue";
import User from "./page/User.vue";
import Goods from "./page/Goods.vue";
import Order from "./page/Order.vue";
export default {
  name: "App",
  data() {
    return {
      page: "Home",
    };
  },
  components: {
    // 注册
    Home,
    User,
    Goods,
    Order,
  },
  methods: {
    toggle(page) {
      this.page = page;
    },
  },
};
</script>

<style>
* {
  padding: 0;
  margin: 0;
}
.container {
  display: flex;
}
.container .left {
  width: 230px;
  height: 100vh;
  background-color: #333;
}
.container .right {
  /* 可以实现不同单位之间的换算 */
  width: calc(100% - 230px);
  height: 100vh;
  background-color: #ddd;
}
.btn {
  width: 100%;
  height: 50px;
  text-align: center;
  line-height: 50px;
  color: #fff;
  cursor: pointer;
}
.header {
  width: 100%;
  height: 60px;
  line-height: 60px;
  background-color: #fff;
}
.content {
  margin: 20px;
  background-color: #fff;
  height: 550px;
  border-radius: 10px;
  padding: 10px;
}
.active {
  background-color: rgb(16, 134, 189);
}
</style>
